package com.ylbh.modules.cashaudit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylbh.common.pojo.cashaudit.dto.CashAuditPassDTO;
import com.ylbh.common.pojo.cashaudit.dto.CashAuditDTO;
import com.ylbh.common.pojo.cashaudit.dto.DiscountRecordDTO;
import com.ylbh.common.pojo.cashaudit.dto.MerchantIncomeListDTO;
import com.ylbh.common.pojo.cashaudit.vo.*;
import com.ylbh.modules.business.entity.ShoppingUser;
import com.ylbh.modules.cashaudit.entity.BusinessWithRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 * @author czx
 * @date 2019-05-04 10:01:32
 */
@Mapper
@Repository
public interface BusinessWithRecordMapper extends BaseMapper<BusinessWithRecord> {

    /**
     * 提现审核列表
     * @param cashAuditDTO
     * @return
     */
    List<CashAuditListVO> selectCashAuditList(@Param(value = "cashAuditDTO")CashAuditDTO cashAuditDTO, Page page);

    /**
     * 查询平台可提现余额
     * @return
     */
    CashAuditVO selectCashAbleBalanceByStatus();

    /**
     * 周提现次数
     * @param id
     * @return
     */
    Integer selectCountById(@Param(value = "id")Long id);

    /**
     * 周提现总金额
     * @param id
     * @return
     */
    BigDecimal selectWeekMoney(@Param(value = "id")long id);

    /**
     * 周和月内提现列表
     * @param cashAuditDTO
     * @return
     */
    List<CashAuditListVO> selectWeekAndMonthCashWithdrawalList(@Param(value = "cashAuditDTO")CashAuditDTO cashAuditDTO, Page page);

    /**
     * 提现审核操作
     * @param id
     * @param type
     */
    void updateCashAudit(@Param(value = "id")String id, @Param(value = "type")Integer type, @Param(value = "trxNo")String trxNo,@Param(value = "noPass") String noPass, @Param(value = "accType") Integer accType);

    /**
     * 提现详情
     * @param id
     * @return
     */
    DetailsOfPresentationVO selectDetailsOfPresentationById(@Param(value = "id")Long id);

    /**
     * 商家收益列表
     * @param merchantIncomeListDTO
     * @param page
     */
    List<MerchantIncomeListVO> selectMerchantIncomeList(@Param(value = "merchantIncomeListDTO") MerchantIncomeListDTO merchantIncomeListDTO, Page page);

    /**
     * 商家收益详情-线上
     * @param id
     * @return
     */
    DetailsOfEarningsAndOnLineVO selectDetailsOfEarningsAndOnLineById(@Param(value = "id")Long id);

    /**
     * 商家收益详情-线下
     * @param id
     * @return
     */
    DetailsOfEarningsAndUnderTheLineVO selectDetailsOfEarningsAndUnderTheLineById(@Param(value = "id")Long id);

    /**
     * 商家收益详情-推广
     * @param id
     * @return
     */
    DetailsOfEarningsAndExtensionVO selectDetailsOfEarningsAndExtensionById(@Param(value = "id")Long id);

    /**
     * 查询出指定商家下所有浪费金额
     * @param id
     * @return
     */
//    List<Object> selectTotalMoneyById(@Param(value = "id")Long id);
    BigDecimal selectTotalMoneyById(@Param(value = "id")Long id);

    /**
     * 推广可提现余额/未提现余额
     * @param id
     */
    RecommendedBalanceVO selectRecommendedBalanceById(@Param(value = "id")Long id);

    void insertBalanceLog(@Param(value = "cashAuditPassDTO") CashAuditPassDTO cashAuditPassDTO);

    int selectAdminUserType(Long createUserId);

    /**
     * 待提现审核的记录数
     * @return
     */
    Integer selectWithRecordCount();

    /**
     * 提现记录
     * @param discountRecordDTO
     * @param page
     * @return
     */
    List<DiscountRecordVO> selectDiscountRecordList(@Param(value = "discountRecordDTO") DiscountRecordDTO discountRecordDTO, Page<Object> page);

    /**
     * 线上订单
     * @param no
     * @return
     */
    SonDiscountRecordVO selectSonDiscountRecord(String no);

    /**
     * 买单
     * @param no
     * @return
     */
    SonDiscountRecordVO selectSonDiscountRecords(String no);

    /**
     * 不通过将交易明细表中的提现记录改为未提现状态
     * @param no
     */
    void updatePayInfo(String no);

    /**
     * 不通过将联盟店订单表中的提现记录改为未提现状态
     * @param no
     */
    void updateBusinessOrder(String no);

    BigDecimal selectPaymentAmountById(ArrayList<String> list);

    Integer selectPaymentVouchersById(ArrayList<String> list);

    List<CashAuditExcel> cashAuditExcel(String keywords, String accType, String cashStatus);

    String selectBusinessGoodsByOrderId(Long id);

    /**
     * 提现审核详情子订单信息
     * @param id
     * @param page
     * @return
     */
    List<String> getSonOrderDetailsById(String id, Page<Object> page);

    /**
     * 未提现的
     * @param id
     * @return
     */
    BigDecimal selectNotExtractById(Long id);

    /**
     * 查询用户的余额信息
     * @param withUserId
     * @return
     */
    ShoppingUser selectUserByWithUserId(Long withUserId);

    /**
     * 根据时间来筛选提现记录
     * @param startTime
     * @param endTime
     * @return
     */
    List<DiscountRecordVO> selectCashWithdrawalRecordByTime(String startTime, String endTime, String userName);
}
